<template>
  <el-row>
    <el-col :span="16">
      <div class="loginbg"></div>
    </el-col>
    <el-col :span="8" class="loginrightT1">
      <div class="loginright">
        <img src="../../assets/imgs/gyklogo.png" alt="" width="130px">
        <p style="font-weight:600;font-size:35px;color:#37474F;margin-top:px;">广应科在线考试系统</p>
        <el-form  :model="ruleForm" :rules="rules" ref="ruleForm" style="margin-left: -100px;" label-width="100px" 
          class="demo-ruleForm">
          <el-form-item prop="username">
            <el-input v-model="ruleForm.username" placeholder="请输入账号|手机|邮箱"></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input v-model="ruleForm.password" show-password placeholder="请输入内容"></el-input>
          </el-form-item>
          <el-form-item prop="checkbox">
            <el-checkbox v-model="checked">自动登录</el-checkbox> <el-link type="primary">主要链接</el-link>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')" style="width:100%;">立即登录</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-col>
  </el-row>
</template>

<script>
  export default {
    data() {
      return {
        ruleForm: {
          username: '',
          password: '',
        },
        rules: {
          username: [
            { required: true, message: '请输入活动名称', trigger: 'blur' },
            { min: 5, max: 18, message: '长度在 5 到 18 个字符', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '密码不能为空', trigger: 'change' }
          ],
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$store.dispatch('user/login', this.ruleForm).then(() => {
              this.$router.push({ path: this.redirect || '/' })
              this.loading = false
          }).catch(() => {
            this.loading = false
          })

          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style scoped>
.loginbg{
  background-image: url('../../assets/imgs/login.jpg');
  width: 100%;
  height: 100vh;
}

.loginright{
  width: 380px;
  height: 460px;
  text-align: center;
}
.loginrightT1{
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>